﻿using System;
using GC_RF.DataAccess.Abstractions.Interfaces.Factories;
using GC_RF.DataAccess.Abstractions.Interfaces.Helpers;
using GC_RF.Domain.Abstractions.Interfaces.Factories;
using GC_RF.Domain.Abstractions.Interfaces.Services;
using GC_RF.Domain.Services;

namespace GC_RF.Domain.Factories
{
	public class ServiceFactory : IServiceFactory
	{
		#region Variables

		private readonly IUnitOfWork _unitOfWork;
		private readonly IRepositoryFactory _repositoryFactory;
		private readonly IHelperFactory _helperFactory;

		#endregion

		#region Constructors

		public ServiceFactory(IUnitOfWork unitOfWork, IRepositoryFactory repositoryFactory, IHelperFactory helperFactory)
		{
			if (unitOfWork == null)
				throw new ArgumentNullException(string.Format("unitOfWork"));
			_unitOfWork = unitOfWork;

			if (repositoryFactory == null)
				throw new ArgumentNullException(string.Format("repositoryFactory"));
			_repositoryFactory = repositoryFactory;

			if (helperFactory == null)
				throw new ArgumentNullException(string.Format("helperFactory"));
			_helperFactory = helperFactory;
		}

		#endregion

		#region IServiceFactory Members

		public IUserService CreateUserService()
		{
			return new UserService(_unitOfWork, _repositoryFactory, _helperFactory.CreateCryptographicAdapter());
		}

		public IAuthenticationService CreateAuthenticationService()
		{
			return new AuthenticationService();
		}

		public INewsService CreateNewsService()
		{
			return new NewsService(_unitOfWork, _repositoryFactory);
		}

		#endregion
	}
}
